package chapter9;

import java.text.DecimalFormat;

public class Demo1 {
    public static void main(String[] args) {
        SimgleFormat("###,###.###",123456.789);
        SimgleFormat("000000000.###kg",123456.789);

        SimgleFormat("000000.000",123.78);

        useApplyMethodPattern("#.###%", 0.789);

        useApplyMethodPattern("###.##", 123456.789);

        useApplyMethodPattern("0.00\u2030", 0.789);
    }

    public static void SimgleFormat(String pattern, double value){
        //实例化DecimalFormat对象
        DecimalFormat myFormat = new DecimalFormat(pattern);
        String output = myFormat.format(value);
        System.out.println(value + " " + pattern + " " + output);
    }

    public static void useApplyMethodPattern(String pattern, double value){
        DecimalFormat myFormat = new DecimalFormat();
        myFormat.applyPattern(pattern);
        System.out.println(value + " " + pattern + " " + myFormat.format(value));
    }
}
